from typing import Dict, Optional, Any
from config.settings import config
from utils.http_client import HttpClient
from .api_response import ApiResponse


class BaseClient:
    """API基础客户端类"""

    def __init__(self):
        self.http_client = HttpClient()
        self.host = config.host
        self.account_host = config.account_host

    def _get(self, endpoint: str, token: Optional[str] = None,
             params: Optional[Dict] = None) -> ApiResponse:
        """发送GET请求"""
        url = f"{self.host}{endpoint}"
        response = self.http_client.get(url, token=token, params=params)
        return ApiResponse(response)

    def _post(self, endpoint: str, data: Optional[Dict] = None,
              token: Optional[str] = None) -> ApiResponse:
        """发送POST请求"""
        url = f"{self.host}{endpoint}"
        response = self.http_client.post(url, json=data, token=token)
        return ApiResponse(response)

    def _put(self, endpoint: str, data: Optional[Dict] = None,
             token: Optional[str] = None) -> ApiResponse:
        """发送PUT请求"""
        url = f"{self.host}{endpoint}"
        response = self.http_client.put(url, json=data, token=token)
        return ApiResponse(response)

    def _delete(self, endpoint: str, token: Optional[str] = None) -> ApiResponse:
        """发送DELETE请求"""
        url = f"{self.host}{endpoint}"
        response = self.http_client.delete(url, token=token)
        return ApiResponse(response)